#ifndef __GLF_MEMORYSTREAM_H_INCLUDED__
#define __GLF_MEMORYSTREAM_H_INCLUDED__

#include <glf/io/stream.h>
#include <glf/io/fileStream.h>

namespace glf {

struct MemoryStream : public IOStream
{
	MemoryStream();
	MemoryStream(void* buffer, size_t size, bool isOwner = false);
	MemoryStream( FileStream& file );

	virtual ~MemoryStream();

	void LoadFileStream( FileStream& file );

	bool Open(void* buffer, size_t size, bool isOwner = false);
	virtual void Close();

	virtual size_t GetSize() const;
	virtual bool CanSeek() const;
	bool CanCancel() const;
	virtual bool CanRead() const;
	virtual bool CanWrite() const;

	virtual size_t Tell()  const;
	virtual bool Seek(int offset, seek origin);

	virtual size_t Read(void* buffer, size_t size);
	virtual size_t Write(const void* buffer, size_t size);

	char* GetBuffer() {
		return mBuffer;
	}
	char* GetPtr() {
		return mBuffer + mFilePosition.Tell();
	}
	const char* GetBuffer() const {
		return mBuffer;
	}
	const char* GetPtr() const {
		return mBuffer + mFilePosition.Tell();
	}

protected:
	bool  mIsOwner;
	char* mBuffer;
};


} //namespace glf

#endif
